Welcome

Best Practices and Strategies to Create Effective Visualizations

Aaron R. Williams

@awunderground

urban-logo

Best Practices and Strategies to Create Effective Visualizations

Why I Use R

Aaron Williams

@awunderground

urban-logo

DYNASIM

Synthetic Data

cart

Outline

  1. WHY: Principles for selecting a data viz tool
  2. WHAT: R and ggplot2
  3. HOW: The theory behind R and ggplot2
  4. Examples
  5. Grade my decision

WHY: Principles for selecting a data viz tool

1. Looks good!

ledecky

Source: fivethirtyeight

2. Flexible and expressive

3. Reproducible

4. Scalable

AKA “Please just don’t make me point-and-click 100 charts”

cat

5. In my analysis workflow

parallel

WHAT: R and ggplot2

Source: Hadley Wickham

Source: ggplot2

fivethirtyeight

Financial Times

BBC

BBC R Cookbook

HOW: Grammar of Graphics

Leland Wilkinson

Grammar of Graphics

Hadley Wickham

A Layered Grammar of Graphics

hadley

Source: Hadley Wickham

1. Data

name year category lat long wind pressure
Richard 2010 0 15.8 -82.1 40 1006
Dean 1989 2 34.0 -64.9 90 968
Allison 1995 1 24.7 -86.2 65 987
Chantal 1995 0 21.1 -64.9 35 1008
Nadine 2012 0 17.5 -44.8 35 1004
Gustav 1990 1 39.4 -50.9 75 978
Pablo 1995 0 11.5 -41.9 50 997
Beryl 1994 0 29.7 -85.6 35 1007
Jeanne 2004 1 27.6 -69.5 75 972
Richard 2010 0 16.7 -80.6 35 1006

ggplot(data = )

2. Aesthetic mappings

aes(x = , y = , color = )

X or Y

Color or Fill

Aesthetic mappings

Size

Shape

Others: transparency, animations, faceting

3. Geometric objects

Plots are often called their geometric object(s).

geom_bar() or geom_col()

3. Geometric objects

geom_line()

3. Geometric objects

geom_point()

3. Geometric objects

?

3. Geometric objects

Path of Hurricane Katrina

4. Scales

Before

scale_x_continuous()

After

scale_x_log10()

4. Scales

Before

scale_size_continuous(breaks = c(25, 75, 125))

After

scale_size_continuous(range = c(0.5, 20), breaks = c(25, 75, 125))

5. Coordinate systems

Cartesian

5. Coordinate systems

Polar

coord_polar()

6. Facets (optional)

Facet wrap

facet_wrap(~category)

6. Facets (optional)

Facet grid

facet_grid(month~status)

7. Statistical transformations (optional)

Count

8. Themes

Default theme

8. Themes

fivethirtyeight theme

8. Themes

urbnthemes

Coding example

stop

New? 9. Arrangements

arrangement

New? 9. Arrangements

arrangement

Source: Policyviz by Jon Schwabish

New? 9. Arrangements

Animation

houston

By Sarah Strochak

10. Interactivity?

frontier

Examples

urbnmapr

Pension code

3.2, 4.2, 4.3, 4.7, 5.12

R Shiny

https://www.urban.org/policy-centers/cross-center-initiatives/program-retirement-policy/projects/dynasim-visualizing-older-americans-future-well-being/fiscal-health-social-security

Graphics guide

Strengths and Weaknesses

1. Looks good!

A

2. Flexible and expressive

B

Once you understand ggplot2, it is really useful for doing 90% of the results with 10% of the effort

(Jennfer Hill)

3. Reproducible

A+

4. Scalable

B+

5. In my analysis workflow

A+

Questions